/* function repeat(cb, count, time) {
    // 
    let ti = count
    let pick
    return function (thing) {
        let that = this
        pick = setInterval(() => {
            if (ti <= 0) {
                clearInterval(pick)
                return
            }
            ti--
            cb.call(that,thing)

        }, time)
    }
}
const repeatFunc = repeat(console.log, 4, 1000)
repeatFunc("helloworld") */

/* function Stack(){
    this.a = []
}
Stack.prototype = {
    In:function In(num){
        this.a.push(num)
    },
    Out:function Out(){
        return this.a.pop()
    },
    Peek:function Peek(){
        return this.a[this.a.length - 1]
    },
    Look:function Look(){
        return this.a
    }
}
let s = new Stack()
s.In(11)
s.In(15)
console.log(s.Look())
console.log(s.Out())
console.log(s.Peek())
console.log(s.Look()) */



/* class Stack{
    constructor(){
        this.a = []
    }
    In(num){
        this.a.push(num)
    }
    Out(){
        return this.a.pop()
    }
    Peek(){
        return this.a[this.a.length - 1]
    }
    Look(){
        return this.a
    }
}
let s = new Stack()
s.In(11)
s.In(15)
console.log(s.Look())
console.log(s.Out())
console.log(s.Peek())
console.log(s.Look()) */

/* let i = 1
for(i ; i < 1; i++){

}
console.log(i) */

/* (function() {
    var x = y = 10;
    var a = 12
    aab = 13
 })();
 alert(y); */
/*  let a = 2,b = 3,c = 10
 console.log(a,b,c)
 let str = '12'
 str.eq */

 // 实现一个函数的柯里化，add(5,2)(4)(1)

/*  function add(){
     let res = 0
     let args = arguments
     console.log(args) 

 }
 add(4,6,8) */

/*  function Person(name,age){
     this.name = name
     this.age = age
 }
 Person.prototype = {
     say:function(){
         console.log("我是"+this.name)
     }
 }
 var a =  person('ff',20)
 console.log(a)
 a.say() */
// 防抖
/* function con(){
    console.log('click')
}
 function throt(fn,delay){
     let time = null

     return function(){
         clearInterval(time)
         time = setTimeout(()=>{
            fn()
         },delay)
     }
 }
 function doub(fn,delay){
     let is = true

     return function(){
         if(!is) return
         is = false
         setTimeout(()=>{
             fn()
             is = true
         },delay)
     }
 }
 let p = document.querySelector('#title').addEventListener('click',doub(con,1000))
 console.log(p) */
// 这里深拷贝只考虑到了数组和对象，没考虑函数
function deepArr(arr){
    let res = []
    for(let i = 0; i < arr.length; i++){
        if(Object.prototype.toString.call(arr[i]) === '[object Array]'){
            res.push(deepArr(arr[i]))
        }else if(Object.prototype.toString.call(arr[i]) === '[object Object]'){
            res.push(deepClone(arr[i]))
        }else{
            res.push(arr[i])
        }
    }
    return res
}
 function deepClone(obj){
     let res = Object.create(null)
     let keys = Object.keys(obj)
     for(let i =0; i < keys.length; i++){
         let key = keys[i]
         let val = obj[key]
        //  这样会将数组拷贝成对象
        /* if(typeof(val) === 'object'){
            res[key] = deepClone(val)
        } */
        if(Object.prototype.toString.call(val) === '[object Object]'){
            res[key] = deepClone(val)
        }else if(Object.prototype.toString.call(val) === '[object Array]'){
            res[key] = deepArr(val)
        }else{
            res[key] = val
        }
     }
     return res
 }
 let obj = {
     name:{
         firstName:'li',
         lastName:'hua',
         info:[1,10]
     },
     age:20,
     list:[1,4,6],
     goal:[
         {math:90},
         {chinese:100}
     ]
 }
 let copy = deepClone(obj)
 console.log(copy)


 function Quick(arr,low,hight){
    let len  = arr.length
    let _low = low
    let _hight = hight
    while(arr[low] <= arr[hight]){
        hight--
    }
    if(arr[low] > arr[hight]){
        let temp = arr[low]
        arr[low] = arr[hight]
        arr[hight] = temp
    }
    while(arr[low] <= arr[hight]){
        low--
    }
    if(arr[low] > arr[hight]){
        let temp = arr[low]
        arr[low] = arr[hight]
        arr[hight] = temp
    }
    //左半部分快排
    Quick(arr,_low,low)
    //右半部分快排
    Quick(arr,low+1,_hight)
  }
  
  function Quick(arr,low,hight){
    let len  = arr.length
    let _low = low
    let _hight = hight
    while(arr[low] <= arr[hight]){
        hight--
    }
    if(arr[low] > arr[hight]){
        let temp = arr[low]
        arr[low] = arr[hight]
        arr[hight] = temp
    }
    while(arr[low] <= arr[hight]){
        low--
    }
    if(arr[low] > arr[hight]){
        let temp = arr[low]
        arr[low] = arr[hight]
        arr[hight] = temp
    }
    //左半部分快排
    Quick(arr,_low,low)
    //右半部分快排
    Quick(arr,low+1,_hight)
  }
  
  // 数组的每个索引为一个阶梯，第i个阶梯对应着一个非负数的体力值cost[i]
  
  // 每当你爬上一个阶梯，都需要花费对应的体力值，之后可以选择继续爬一个阶梯或两个阶梯。
  
  // 你需要找到到达顶楼的最低花费。
  
  /* 在开始时，你可以选择从索引为0或1的阶梯作为初始阶梯。
  
  示例1: 输入：cost = [10，15，20] 输出：15 解释：最低花费从cost[1]开始，走两步即可到达顶楼，共花费15体力值。
  
  示例2: 输入：cost = [1, 100，1, 1, 1, 100，1, 1, 100, 1] 输出：6 解释：最低花费从cost[0]开始，逐个经过1，跳过cost[3], 到达顶楼，共花费6体力值。
  function Sol(arr){
    let len = arr.length
    //定义f[n
  } */
  
  var minCostClimbingStairs = function(cost) {
    let len = cost.length
    let f = new Array(len + 1)
    //f[n]表示到达当前位置的最小花费，f[n]就表示楼顶
    f[0] = cost[0]
    f[1] = cost[1]
    const[len] = 0
    for(let n = 2; n <= len; n++){
        f[n] = Math.min(f[n-1],f[n-2]) + cost[n]
    }
    return f[len]
  };
  let a = minCostClimbingStairs(
    [10,15,20])
    console.log(a)